<!DOCTYPE html>
<html>

<head>
    <title>VectorFieldAnim / Style</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" href="//unpkg.com/leaflet@1.2.0/dist/leaflet.css" />
    <link rel="stylesheet" href="examples.css" />
    <link href="https://fonts.googleapis.com/css?family=Roboto:100,400" rel="stylesheet">
</head>

<body>
    <h1 class="title mapTitle">VectorFieldAnim styles</h1>
    <div id="map"></div>

    <!-- CDN -->
    <script src="//d3js.org/d3.v4.min.js"></script>
    <script src="//npmcdn.com/leaflet@1.2.0/dist/leaflet.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/chroma-js/2.1.0/chroma.min.js"></script>

    <!-- Plugin -->
    <script src="dist/leaflet.canvaslayer.field.js"></script>

    <script>
        let map = L.map("map");
        let url = 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_nolabels/{z}/{x}/{y}.png';
        L.tileLayer(url, {
            attribution: 'OSM & Carto',
            subdomains: 'abcd',
            maxZoom: 19
        }).addTo(map);

        // Vectorfield animations with custom parameters
        d3.text('data/Atlantic_U.asc', function (u) {
            d3.text('data/Atlantic_V.asc', function (v) {
                let vf = L.VectorField.fromASCIIGrids(u, v, 0.001); // scalefactor to get units in m/s

                let layer = L.canvasLayer.vectorFieldAnim(vf, {
                    paths: 100,
                    color: "#FF6699",
                    width: 3,
                    velocityScale: 1 / 10,
                    mouseMoveCursor: null
                }).addTo(map);

                var layer2 = L.canvasLayer.vectorFieldAnim(vf, {
                    paths: 10000,
                    color: "cyan",
                    width: 0.5,
                    fade: 0.92,
                    maxAge: 2000,
                    velocityScale: 1 / 100,
                    mouseMoveCursor: null
                }).addTo(map);

                map.fitBounds(layer.getBounds());

                // Change color of layer2, every n secs.
                var colors = ['cyan', 'yellow', 'pink', 'aqua', 'DeepSkyBlue'];
                setInterval(function () {
                    var r = Math.random() * colors.length | 0;
                    layer.options.color = colors[r];
                }, 5000);
            });
        });
    </script>
</body>

</html>